﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Diagnostics;

namespace 线程的信号机制
{
    class Program
    {
        
        static void Main(string[] args)
        {
            var stopwatch = new Stopwatch();
            stopwatch.Start();
            var signal = new ManualResetEvent(false);
            new Thread(
                ()=> {//匿名委托的
                    Console.WriteLine("Waiting for signal...");
                    signal.WaitOne();
                    signal.Dispose(); Console.WriteLine("Got signal!");

                }).Start();
            stopwatch.Restart();
            Thread.Sleep(2000);
            signal.Set();// 打开“信号”
            stopwatch.Restart();
            Console.ReadKey();
        }
    }
}
